package com.arron.juc;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Classname CyclicBarrierDemo
 * @Description TODO
 * @Date 2020/8/21 15:11
 * @Created by 刘
 */
public class CyclicBarrierDemo {

    /**
     * 集齐7颗龙珠，召唤神龙
     * 等7个人都到了，再开会
     * @param args
     */
    public static void main(String[] args) {

        CyclicBarrier cyclicBarrier = new CyclicBarrier(7, () -> {
            System.out.println("7个员工到齐了，会长准备开会");
        });

         for (int i = 1; i <= 7; i++) {
             new Thread(()->{
                 try {
                     System.out.println(Thread.currentThread().getName()+"员工\t 到了");
                     cyclicBarrier.await();
                 } catch (InterruptedException e) {
                     e.printStackTrace();
                 } catch (BrokenBarrierException e) {
                     e.printStackTrace();
                 }
             },String.valueOf(i)).start();
         }

    }

}
